using Autofac.Extensions.DependencyInjection;
using Loong.Configuration;
using Loong.Domain.Uow;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Loong.Web.Api
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                var connectionString = config.Build().GetSection(ConnectionStringOptions.SectionName)[ConnectionStringOptions.ConnectionName];
                config.AddDbConfiguration(builder =>
                {
                    builder.UseMySql(connectionString);
                });
            })
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
    }
}
